<?php
namespace app\admin\controller;

use app\BaseController;
use app\Request;
use app\admin\model\{SystemAdmin as SystemAdminModel};
use app\admin\validate\{SystemAdminCreateValidate, SystemAdminUpdateValidate, SystemUpdateValidate};

class SystemAdmin extends BaseController
{
    public function updateAdminPass(Request $request)
    {
        $validate = new SystemUpdateValidate();
        $validate->checkParams();
        $data = $validate->getDataByRule($request->post());

        $this->success('success', SystemAdminModel::systemUpdate($data), 201);
    }

    public function createAdmin(Request $request) 
    {
        (new SystemAdminCreateValidate())->checkParams();
        $data = $request->post();

        $this->success('success', SystemAdminModel::adminCreate($data), 201);
    }

    public function updateAdmin(Request $request) 
    {
        (new SystemAdminUpdateValidate())->checkParams();
        $data = $request->post();

        $this->success('success', SystemAdminModel::adminUpdate($data), 201);
    }


    public function adminList(Request $request)
    {
        $params = $request->get();
        $this->success('success', SystemAdminModel::adminList($params), 200);
    }

    public function updateState(Request $request)
    {
        $data = $request->param();
        $this->success('success', SystemAdminModel::updateState($data['id']), 204);
    }
}